/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "user_invitation", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "GroupInvitation.findAll", query = "SELECT g FROM GroupInvitation g"),
    @NamedQuery(name = "GroupInvitation.findByGroupId", query = "SELECT g FROM GroupInvitation g WHERE g.groupInvitationPK.groupId = :groupId"),
    @NamedQuery(name = "GroupInvitation.findBySourceUserId", query = "SELECT g FROM GroupInvitation g WHERE g.groupInvitationPK.sourceUserId = :sourceUserId"),
    @NamedQuery(name = "GroupInvitation.findByDestUserId", query = "SELECT g FROM GroupInvitation g WHERE g.groupInvitationPK.destUserId = :destUserId"),
    @NamedQuery(name = "GroupInvitation.findByIsApproved", query = "SELECT g FROM GroupInvitation g WHERE g.isApproved = :isApproved")})
public class GroupInvitation implements Serializable, IGroupInvitation {
    @JoinColumn(name = "role_id", referencedColumnName = "role_id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Role roleId;
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId 
    protected GroupInvitationPK groupInvitationPK;
    @Basic(optional = false)
    @Lob
    @Column(name = "comment", nullable = false, length = 65535)
    private String comment;
    @Basic(optional = false)
    @Column(name = "isApproved", nullable = false)
    private short isApproved;
    @JoinColumn(name = "dest_user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User destUser;
    @JoinColumn(name = "source_user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User sourceUser;
    @JoinColumn(name = "group_id", referencedColumnName = "group_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GroupEx groupEx;

    public GroupInvitation() {
    }

    public GroupInvitation(GroupInvitationPK groupInvitationPK) {
        this.groupInvitationPK = groupInvitationPK;
    }

    public GroupInvitation(GroupInvitationPK groupInvitationPK, String comment, short isApproved) {
        this.groupInvitationPK = groupInvitationPK;
        this.comment = comment;
        this.isApproved = isApproved;
    }

    public GroupInvitation(int groupId, int sourceUserId, int destUserId) {
        this.groupInvitationPK = new GroupInvitationPK(groupId, sourceUserId, destUserId);
    }

    public GroupInvitationPK getGroupInvitationPK() {
        return groupInvitationPK;
    }

    public void setGroupInvitationPK(GroupInvitationPK groupInvitationPK) {
        this.groupInvitationPK = groupInvitationPK;
    }

    @Override
    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public short getIsApproved() {
        return isApproved;
    }

    public void setIsApproved(short isApproved) {
        this.isApproved = isApproved;
    }

    @Override
    public User getDestUser() {
        return destUser;
    }

    public void setDestUser(User user) {
        this.destUser = user;
    }

    @Override
    public User getSourceUser() {
        return sourceUser;
    }

    public void setSourceUser(User user1) {
        this.sourceUser = user1;
    }

    @Override
    public GroupEx getGroupEx() {
        return groupEx;
    }

    public void setGroupEx(GroupEx groupEx) {
        this.groupEx = groupEx;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (groupInvitationPK != null ? groupInvitationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GroupInvitation)) {
            return false;
        }
        GroupInvitation other = (GroupInvitation) object;
        if ((this.groupInvitationPK == null && other.groupInvitationPK != null) || (this.groupInvitationPK != null && !this.groupInvitationPK.equals(other.groupInvitationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cs575.dbentities.GroupInvitation[ groupInvitationPK=" + groupInvitationPK + " ]";
    }

    @Override
    public Role getRoleId() {
        return roleId;
    }

    public void setRoleId(Role roleId) {
        this.roleId = roleId;
    }
    
}
